package com.LeeCode;

/**
 * 全 0 子数组的数目
 */

public class Code2348 {
    public static void main(String[] args) {
        int[] nums = {0, 0, 0, 2, 0, 0};
        System.out.println(new Code2348().zeroFilledSubarray(nums));
    }

    public long zeroFilledSubarray(int[] nums) {
        int count = 0;
        long ans = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                count++;
                if (i == nums.length - 1) {
                    ans += (1L + count) * count / 2;
                }
            } else {
                ans += (1L + count) * count / 2;
                count = 0;
            }
        }
        return ans;
    }
}
